package com.ddwl.goods.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.goods.service.SignHistService;
import com.ddwl.goods.service.SignInService;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.goods.SignHistBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.goods.SignHistVo;
import com.ddwl.schema.vo.goods.SignInVo;
import com.ddwl.schema.vo.goods.SignVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.Instant;

/**
 * @Author hemiaojun
 * @Date 2020/10/19 17:13
 */
@RestController
@RequestMapping("/sign")
@Api(tags = "用户签到")
public class SignController extends BaseController {

    @Resource
    private SignInService signInService;
    @Resource
    private SignHistService signHistService;

    @PostMapping("/signIn")
    @Auth(product = {BaseEnum.ProductEnum.FENXIAO,BaseEnum.ProductEnum.MALL})
    @ApiOperation("签到")
    public RestVo<SignInVo> signIn(){
        return RestVo.ok(signInService.signIn(getUserId()));
    }

    @PostMapping("/history/page")
    @Auth(product = {BaseEnum.ProductEnum.CONSOLE})
    @ApiOperation("后台签到列表")
    public RestVo<PageVo<SignHistVo>> page(@RequestBody PageBo<SignHistBo> bo){
        return RestVo.ok(signHistService.page(bo));
    }

    @GetMapping("/list")
    @Auth(product = {BaseEnum.ProductEnum.FENXIAO,BaseEnum.ProductEnum.MALL})
    @ApiOperation("app签到记录展示")
    public RestVo<SignVo> list(){
        return RestVo.ok(signHistService.list(getUserId()));
    }

    @PostMapping("/reissue")
    @Auth(product = {BaseEnum.ProductEnum.FENXIAO,BaseEnum.ProductEnum.MALL})
    @ApiOperation("app补签")
    public RestVo<SignInVo> reissue(@RequestParam("signDate") Instant signDate){
        return RestVo.ok(signInService.reissue(getUserId(),signDate));
    }

}
